{extend name='app' /}
{block name='title'}管理员列表{/block}

{block name="stylesheet"}
<link href="{__ADMIN__}/css/plugins/steps/jquery.steps.css" rel="stylesheet">
{/block}


{block name="breadcrumb"}
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>权限规则</h2>
        <ol class="breadcrumb">
            <li class="breadcrumb-item">
                <a>权限管理</a>
            </li>
            <li class="breadcrumb-item active">
                <strong>权限规则</strong>
            </li>
        </ol>
    </div>
</div>
{/block}


{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <form id="block-search">

                            <div class="row ">
                                <div class="col-sm-3">
                                    <div class="form-group">
                                        <label class="control-label">切换系统:</label>
                                        <select class="form-control m-b select-title" name="system_id">
                                            <option value="1" {if $system_id==1} selected {/if} >总后台系统</option>
                                            <option value="2" {if $system_id==2} selected {/if}>门店系统</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <p><strong>温馨提示：</strong></p>
                                    <p> 1. 修改节点位置必须点击 <span class="text-warning">保存</span> 才会生效</p>
                                </div>
                            </div>
                                <div class="row m-b-lg">
                                    <div class="col-sm btn-group-search">
                                        <button class="btn btn-primary btn-sm" type="submit">确定</button>
                                        <button class="btn btn-white btn-sm btn-reset" type="button">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
            </div>
    </div>

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox ">

                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-12 m-b-sm">
                                <span class="float-left">
                                    <button class="btn btn-primary btn-sm" type="button"
                                            onclick="get_html($(this),'{$Think.config.admin.app_host}/admin/rule/create?system_id={$system_id}')"><i
                                            class="fa fa-plus"></i>&nbsp;添加
                                    </button>
                                </span>
                            <span class="float-right btn-group">
                                    <button type="button" data-action="collapse-all"
                                            class="btn btn-success btn-xs btn-sm nestable-status">
                                        <i class="fa fa-compress"></i>&nbsp;收起
                                    </button>
                                    <button type="button" class="btn btn-warning btn-xs"
                                            onclick="resort($(this),'{$Think.config.admin.app_host}/admin/rule/resort')">
                                        <i class="fa fa-save"></i>&nbsp;保存
                                    </button>

                                </span>
                        </div>
                    </div>

                    <input type="hidden" name="rule_ids">
                    <div class="dd" id="rule_list">
                        {$list|raw}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script src="{__ADMIN__}/js/plugins/nestable/jquery.nestable.js"></script>
<script>
    $(function () {

        var updateOutput = function (e) {
            var list = e.length ? e : $(e.target), $output;

            if (window.JSON) {
                $output = window.JSON.stringify(list.nestable('serialize'));
                $('input[name="rule_ids"]').val($output);
            } else {
                alert("浏览器不支持");
                return;
            }
        };

        $('#rule_list').nestable({
            group: 1
        }).on('change', updateOutput);
    });

    $(".nestable-status").click(function () {
        var $action = $(this).data("action");

        if ($action === 'expand-all') {
            $('.dd').nestable('expandAll');
            $(this).data("action", "collapse-all");
            $(this).html('<i class="fa fa-compress"></i>&nbsp;收起');
        } else {
            $('.dd').nestable('collapseAll');
            $(this).data("action", "expand-all");
            $(this).html('<i class="fa fa-expand"></i>&nbsp;展开');
        }
    });

    function change_status(that, url) {
        let loading = that.ladda();
        // 加载中按钮显示
        loading.ladda('start');

        var data = {};
        if (that.data('status') == 1) {
            data.status = 0;
        } else {
            data.status = 1;
        }
        let response = post_request(url, data);
        if (response.status == 1) {
            window.location.reload();
        } else {
            let msg = response.msg
            if (!msg) {
                msg = '系统出错了';
            }
            show_tip('提示', msg, 'error');
            // 加载中按钮隐藏
            loading.ladda('stop');
        }
    }

    // 更换节点位置
    function resort(that, url) {
        let rule_ids = $('input[name="rule_ids"]').val();
        if (!rule_ids) {
            show_tip('提示', '保存失败，结构并未修改', 'error');
            return;
        }
        post_data(that, url, {rule_ids: rule_ids})
    }

</script>
{/block}
